package com.oncliedisk.administrator.ui;

import android.view.View;
import android.widget.Toast;

import com.oncliedisk.administrator.onlinedisk.R;
import com.oncliedisk.administrator.utils.ReadDataFromContentProvider;

/**
 * Created by Administrator on 2015/12/1 0001.
 */
public class UploadMusicActivity extends BaseUploadActivity {
    @Override
    public void fillData() {
        data = ReadDataFromContentProvider.readAudio(this);
        if (null == data || data.size() == 0) {
            Toast.makeText(this, "没有扫描到音频文件!", Toast.LENGTH_LONG).show();
            return;
        }

        //加载数据，进度条可见<a
        ll_loading.setVisibility(View.VISIBLE);
        new Thread(new Runnable() {
            @Override
            public void run() {
                data = ReadDataFromContentProvider.readAudio(UploadMusicActivity.this);
                if (null == data || data.size() == 0) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //没有数据加载，进度条不可见
                            ll_loading.setVisibility(View.INVISIBLE);
                            Toast.makeText(UploadMusicActivity.this, "没有扫描到视频文件!", Toast.LENGTH_LONG).show();
                        }
                    });
                    return;
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //数据加载完毕，进度条不可见
                        ll_loading.setVisibility(View.INVISIBLE);
                        if(adapter == null) {
                            adapter = new MyAdapter(UploadMusicActivity.this, data);
                            listview.setAdapter(adapter);
                        }else {
                            adapter.notifyDataSetChanged();
                        }
                    }
                });
            }
        }).start();
    }

    @Override
    protected void setIcon(ViewHolder holder, int position) {
        holder.iv_icon.setImageResource(R.drawable.icon_list_audiofile);
    }
    @Override
    protected void setUploadTitle() {
        tv_title.setText("请选择音乐上传");
    }
}
